<?php

/**
 * contact : 刘经理 19326416371
 * company : 版权所属 四川北星惯牌科技有限公司
 **/

namespace app\common\manager\notify;
use app\common\manager\BaseManager;
use app\common\manager\notify\gateway\Recharge;
use app\common\manager\notify\gateway\Group;
use app\common\manager\notify\gateway\Purchase;
use app\common\manager\notify\gateway\Match;
use app\common\manager\notify\gateway\Withdraw;
use app\common\manager\notify\gateway\Transfer;
use app\common\manager\notify\gateway\Assistant;
use think\Exception;

class NotifyManager extends BaseManager
{
    const RELATION_TYPE_RECHARGE = 'Recharge';
    const RELATION_TYPE_WITHDRAW = 'Withdraw';
    const RELATION_TYPE_GROUP = 'Group';
    const RELATION_TYPE_MATCH = 'Match';
    const RELATION_TYPE_TRANSFER = 'Transfer';
    const RELATION_TYPE_PURCHASE = 'Purchase';
    const RELATION_TYPE_ASSISTANT = 'Assistant';
    private static $result;
    public static function __callStatic ($name,$arguments)
    {
        self::exec($arguments[0],$arguments[1]);
    }

    private static function exec($type,$response)
    {
        try {
            $dealWithManager = null;
            switch ($type) {
                case self::RELATION_TYPE_RECHARGE:
                    $dealWithManager = new Recharge();
                    break;
                case self::RELATION_TYPE_WITHDRAW:
                    $dealWithManager = new Withdraw();
                    break;
                case self::RELATION_TYPE_GROUP:
                    $dealWithManager = new Group();
                    break;
                case self::RELATION_TYPE_MATCH:
                    $dealWithManager = new Match();
                    break;
                case self::RELATION_TYPE_TRANSFER:
                    $dealWithManager = new Transfer();
                    break;
                case self::RELATION_TYPE_PURCHASE:
                    $dealWithManager = new Purchase();
                    break;
                case self::RELATION_TYPE_ASSISTANT:
                    $dealWithManager = new Assistant();
                    break;
            }
            //file_put_contents('callback.log','$response:'.json_encode($response).PHP_EOL,FILE_APPEND);
            $result = $dealWithManager->dealWith($response);
            self::setResult($result);
        }catch (Exception $exception){
            file_put_contents('callback.log',$exception->getMessage().PHP_EOL,FILE_APPEND);
            self::setResult(['code'=>self::$failCode,'message'=>$exception->getMessage()]);
        }


    }

    private static function setResult($result): void
    {
        self::$result = $result;
    }

    public static function getResult()
    {
        return self::$result;
    }
}